package com.star.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * com.star.interceptor
 *
 * @Description: 登录拦截器
 * @Date: 2020-08-05 20:30
 * @Author: LENSTAR
 * @URL: http://123.57.161.114:9000/
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        if (request.getSession().getAttribute("user") == null) {//未登录
            request.setAttribute("msg", "未登录，请先登录！");
            response.sendRedirect("/admin");//重定向到登录页
            return false;
        }
        return true;
    }
}
